package com.framework.service.index.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.framework.entity.or.OrAppMenu;
import com.framework.entity.or.OrAppMenuType;
import com.framework.entity.or.OrBanner;
import com.framework.entity.promotion.ProPromotion;
import com.framework.entity.sys.SysAgent;
import com.framework.service.AgentService;
import com.framework.service.AppMenuService;
import com.framework.service.BannerService;
import com.framework.service.TransactionInfoService;
import com.framework.service.index.IndexService;
import com.framework.service.promotion.ProPromotionService;
import com.framework.utils.bank.BankUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author wq
 */
@Service("indexService")
public class IndexServiceImpl implements IndexService {

    @Autowired
    private AgentService agentService;

    @Autowired
    private TransactionInfoService transactionInfoService;

    @Autowired
    private ProPromotionService proPromotionService;

    @Autowired
    private BannerService bannerService;

    @Autowired
    private AppMenuService appMenuService;

    @Override
    public Map<String, Object> getIndexInfo(String token) {
        Map<String,Object> result=new HashMap<>(5);

        SysAgent agent = agentService.queryAgentByToken(token);

        result.put("name",agent.getName());

        List<ProPromotion> proList = proPromotionService.selectList(new EntityWrapper<ProPromotion>()
                .eq("dept_id", agent.getDeptId())
                .eq("state",1)
                .ge("end_date",new Date())
                .le("start_date",new Date())
                .orderDesc(Arrays.asList(
                        "create_time","sort"
                ))
        );
        result.put("proList",proList);
        List<OrBanner> bannerList = bannerService.queryBannerList(1, agent.getDeptId());
        result.put("bannerList",bannerList);
        List<OrAppMenuType> menuTypes = appMenuService.queryMenuGroupByType(agent.getDeptId());
        result.put("menuTypes",menuTypes);
        Map<String, Object> transMap = transactionInfoService.getIndexTransaction(token, 1);
        result.put("transMap",transMap);

        return result;
    }

    @Override
    public List<String> getBankNameList() {
        List<String> list = BankUtil.getBankNameList();
        return list;
    }


}
